Skip to content

Changes parameter access behavior to not wait on key lookup. - #389

Closed
tcr3dr wants to merge 2 commits into
masterfrom
tcr-paramdefaultbehavior
Closed

tcr3dr wants to merge 2 commits into
masterfrom
tcr-paramdefaultbehavior

Conversation

@tcr3dr

@tcr3dr tcr3dr commented Oct 31, 2015

Copy link
Copy Markdown
Contributor

This behavior seems fairly "magical", requires a hack in Solo, and also .wait_valid() in terms of parameters should be generalized in the .wait('parameters') magic (#342).

@hamishwillee

Copy link
Copy Markdown
Contributor

@tcr3dr Was the wait_valid() waiting for ALL parameters to be downloaded or just the current parameter you queried? If the former then IMO it would be good to add #342 first so that we don't have to poll for the value.

More generally, the later case interests me. Yes we get all parameters on load, but how do we compensate for the possibility they might change - either due to a connected GCS or automatically in autotune?

@tcr3dr

tcr3dr commented Nov 2, 2015

Copy link
Copy Markdown
Contributor Author

@hamishwillee The old behavior of this was to wait for all parameters to be downloaded before parameters['KEY'] returned anything.

So our choice is to:

  1. Accept that accessing a parameter before it is downloaded will throw a KeyError rather than None (like other default attributes do), or
  2. Accept that parameter access is not "cheap", i.e. can enter into a (potentially infinite!) spin-loop waiting for (all) parameter download to occur

I'm strongly against the latter, since it makes property access magical and even network-dependent. It's better to explicitly say where the parameter download behavior should occur. Right now that is possible with the await_params=True flag, which we can update our examples to use.

Basically, I would want my script to a) connect to the drone, b) download the current state of all variables, and c) receive updates over time so that our state always mirrors that of the autopilot. I think that's the case right now with connect(await_params), and is being extended more broadly in #342. Waiting for a single parameter's value can be extended possibly with a .get() method; I think Parameters object already exposes a .set() method with more features. We're simply changing the default property behavior, while allowing the old behavior.

In summary, I would never call .parameters[key] without either explicitly waiting for the initial download, or accepting that we may not know of a parameter's existence yet and code accordingly. Solo, in fact, does the latter with a try: except: construct wrapping Parameter access in its shots code(!).

@hamishwillee

Copy link
Copy Markdown
Contributor

@tcr3dr Thanks Tim - All examples already use await_params=True flag so if the "what we have now" isn't broken by this change it is good for me.

Essentially there are two models a developer might like. The one you describe after "Basically, I would ..." is one model, and the one everyone uses and understands at the moment. The other is where you allow connection without parameters, but people can get individual parameters when they need them. I think you're saying if that they try to get a parameter that has not yet downloaded this will fail.

Anyway, upshot at the moment is that I probably should document this expectation in http://python.dronekit.io/guide/vehicle_state_and_parameters.html#parameters - OK?

@tcr3dr

tcr3dr commented Nov 3, 2015

Copy link
Copy Markdown
Contributor Author

Gonna hold off on this pending more discussion.

@hamishwillee

Copy link
Copy Markdown
Contributor

Either way, we need to have a short discussion in the near future so you can confirm exactly what behaviour parameters has, so I can update the docs.

Are we getting/do we need parameter observers?

My gut feeling is that they are a "nice to have" not a "need" - you'd only really need an observer for maintaining a UI (ie for re-writing a GCS) and in most cases the UI for parameters would tend to be a static set of data that would be opened only for changes (so wouldn't need monitoring)/

@tcr3dr

tcr3dr commented Nov 10, 2015

Copy link
Copy Markdown
Contributor Author

Given that we have .set() and .get() now, it seems users have all the control they need to avoid auto-parameter download behavior. Going to close this.

@tcr3dr tcr3dr closed this Nov 10, 2015
@hamishwillee

Copy link
Copy Markdown
Contributor

Good idea

@tcr3dr
tcr3dr deleted the tcr-paramdefaultbehavior branch November 10, 2015 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants